package com.glorystone.ins.controller;

import com.glorystone.ins.common.common.DataTable;
import com.glorystone.ins.common.common.PageVo;
import com.glorystone.ins.domain.AuditTask;
import com.glorystone.ins.domain.SysUser;
import com.glorystone.ins.interceptor.PageList;
import com.glorystone.ins.service.AuditTaskService;
import com.glorystone.ins.service.ISysUserService;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 审批任务
 * Created by wangwei on 2018/3/13.
 */
@Controller
@RequestMapping("/task")
public class AuditTaskController extends BaseController {

    @Autowired
    private AuditTaskService auditTaskService;
    @Autowired
    private ISysUserService sysUserService;

    @RequestMapping(value = "/tolist", method = RequestMethod.GET)
    public String toChannelView(Model model) {
    	SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
    	SysUser sysUser = sysUserService.getUserById(user.getTid());
    	model.addAttribute("landTime", sysUser.getFirstLand());
    	model.addAttribute("tid", user.getTid());
        return "task/task_list";


    }


    @RequestMapping(value="/queryTableData",method = RequestMethod.GET)
    @ResponseBody
    public DataTable<AuditTask> queryTableData(HttpServletRequest request){
        PageVo vo =  parametToPageVo(request, AuditTask.class);
        PageList<AuditTask> list = auditTaskService.findList(vo);
        DataTable data = resultToDataTable(list);
        return data;
    }

    @RequestMapping(value = "/view_done/{taskId}", method = RequestMethod.GET)
    public void viewDone(@PathVariable("taskId") Long id) {

        auditTaskService.updateViewToDone(id);

    }

}
